<template>
  <div class="auto-course">
    <ul>
      <li>
        <label>当前进化次数：</label>
        <span>{{ editData.jhcs || 0 }}</span>
      </li>
      <li>
        <label>当前耗时：</label>
        <span>{{ currentTime }}</span>
      </li>

      <li>
        <label>排课状态：</label>
        <span>{{ lessonStatus }}</span>
      </li>
      <template v-show="editData.pkzt == '2' || editData.pkzt =='3'">
        <li>
            <el-tooltip placement="top">
                <div slot="content">最高分1分，1分标识排课结果全部满足排课规则，分数越低代表排课结果越差</div>
                <label>排课得分：</label>
            </el-tooltip>
            <span>{{ editData.pkdf }}</span>
        </li>
        <li>
            <label>是否已经写入课表：</label>
            <span>{{ editData.kbxrzt == '1' ? '是' : '否' }}</span>
        </li>
        <li>
            <label>学年学期：</label>
            <span>{{ editData.xqmc}}</span>
        </li>
        <li>
            <label>排课开始周：</label>
            <span>{{ editData.pkksz}}</span>
        </li>
        <li>
            <label>排课结束周：</label>
            <span>{{ editData.pkjsz}}</span>
        </li>
        <li>
            <label>排课老师总数：</label>
            <span>{{ editData.pklszs}}</span>
        </li>
        <li>
            <label>已排课老师总数：</label>
            <span>{{ editData.ypklszs}}</span>
        </li>
        <li>
            <label>排课教室总数：</label>
            <span>{{ editData.pkjszs}}</span>
        </li>
        <li>
            <label>已排课教室总数：</label>
            <span>{{ editData.ypkjszs}}</span>
        </li>
        <li>
            <label>总任务书：</label>
            <span>{{ editData.zrws}}</span>
        </li>
        <li>
            <label>已排任务书：</label>
            <span>{{ editData.zrws - editData.wprws}}</span>
        </li>
        <li>
            <label>未排任务书：</label>
            <span>{{ editData.wprws}}</span>
            &nbsp;&nbsp;&nbsp;&nbsp;<el-button type="primary" @click="openDialog" v-if="editData.wprws>0">查看</el-button>
        </li>
      </template>

    </ul>
      <select-task-book
              ref="selectTaskBook"
              :editId="editData.pkjlid"
              :mapOptions="mapOptions"
              param-type="unUseTaskBook"
      ></select-task-book>
  </div>
</template>

<script>
import course from "@/api/course";

const selectTaskBook = () => import('./SelectTaskBook.vue')
export default {
  components: {
      selectTaskBook
  },
  props: {
    editData: {
      type: Object,
      default: () => {
        return {}
      }
    },
  },
  data() {
      return {
          mapOptions: [],
      }},
  computed: {
    lessonStatus() {
      let obj = {
        0: '未开始',
        1: '进行中',
        2: '完成排课',
        3: '完成排课(部分完成)',
        4: '异常',
      }
      return this.editData.pkzt ? obj[this.editData.pkzt] : ''
    },
    currentTime() {
      if (this.editData.pkhs) {
        return this.changeTime(this.editData.pkhs)
      }
      if (this.editData.pkkssj) {
        return this.getFormatTime(this.editData.pkkssj)
      }
      return '0分0秒'
    }
  },
  created() {
      this.getMapOptions()
  },
  methods: {
    openDialog() {
        this.$refs.selectTaskBook.showDialog()
    },
    getMapOptions() {
        course.getDicListByKeys('aicdic').then(res => {
            this.mapOptions = res.value.aicdic
        })
    },
    changeTime(time) {
      let usedTime = time * 1000 // 相差的毫秒数
      let days = Math.floor(usedTime / (24 * 3600 * 1000)) // 计算出天数
      let leavel = usedTime % (24 * 3600 * 1000) // 计算天数后剩余的时间
      let hours = Math.floor(leavel / (3600 * 1000)) // 计算剩余的小时数
      let leavel2 = leavel % (3600 * 1000) // 计算剩余小时后剩余的毫秒数
      let minutes = Math.floor(leavel2 / (60 * 1000)) // 计算剩余的分钟数
      //计算秒数
      var seconds = Math.round((leavel2 % (60 * 1000)) / 1000)
      return `${days > 0 ? days + '天' : ''}${hours > 0 ? hours + '时' : ''}${
        minutes > 0 ? minutes + '分' : ''
      }${seconds}秒`
    },
    getFormatTime(start) {
      let startTime = new Date(start) // 开始时间
      let endTime = new Date() // 结束时间
      let usedTime = endTime - startTime // 相差的毫秒数
      let days = Math.floor(usedTime / (24 * 3600 * 1000)) // 计算出天数
      let leavel = usedTime % (24 * 3600 * 1000) // 计算天数后剩余的时间
      let hours = Math.floor(leavel / (3600 * 1000)) // 计算剩余的小时数
      let leavel2 = leavel % (3600 * 1000) // 计算剩余小时后剩余的毫秒数
      let minutes = Math.floor(leavel2 / (60 * 1000)) // 计算剩余的分钟数
      //计算秒数
      var seconds = Math.round((leavel2 % (60 * 1000)) / 1000)
      return `${days > 0 ? days + '天' : ''}${hours > 0 ? hours + '时' : ''}${
        minutes > 0 ? minutes + '分' : ''
      }${seconds}秒`
    }
  }
}
</script>

<style lang="scss" scoped>
.auto-course {
  padding: 24px;
  > ul {
    li {
      line-height: 32px;
      display: flex;
      align-items: center;
      font-size: 16px;
      label {
        width: 150px;
        text-align: right;
      }
    }
  }
}
</style>
